<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
class RedV2 extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:redv2';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command redv2';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
		$this->red(10000,100000,5,0.01);
    }
	
 	private function red($money,$fen,$max,$min){
		DB::table('redrain_prize')->delete();
        $total=$money;//红包总额
        $num=$fen;// 分成8个红包，支持8人随机领取
        $min=$min;//每个人最少能收到0.01元

        for ($i=1;$i<$num;$i++){
//          $safe_total=($total-($num-$i)*$min);//随机安全上限
            $safe_total=($total-($num-$i)*$min)/($num-$i);//随机安全上限
            if($safe_total > $max)
            {
                $safe_total = $max;
            }
            $money=mt_rand($min*100,$safe_total*100)/100;
			$total=$total-$money;

			DB::table('redrain_prize')->insert([
				'no'	=> $i,
				'amount'=>$money*100,
				'updated_at'=>date("Y-m-d H:i:s"),
				'created_at' =>date("Y-m-d H:i:s"),
				]);
			echo $i.'.';
        }
		
		$this->line('ok');
    }
	
	
}
